#include "Clazz.h"
#include "Attribute.h"
#include "Method.h"

Clazz::Clazz()
{
    className = QString("");
    methods = QVector<Method*>();
    attributes = QVector<Attribute*>();
    subtypes = QVector<Clazz*>();
    innerClasses = QVector<Clazz*>();
    stereotype = QString("");
}

Clazz::Clazz(QString name){

   this->className = name;
   methods = QVector<Method*>();
   attributes = QVector<Attribute*>();
   subtypes = QVector<Clazz*>();
   innerClasses = QVector<Clazz*>();
   stereotype = QString("");
}

QString Clazz::getClassName()
{
    return className;
}

void Clazz::setClassName(QString className)
{
    this->className = className;
}

QVector<Clazz*> Clazz::getSubtypes()
{
    return subtypes;
}

void Clazz::setSubtypes(QVector<Clazz*> subtypes)
{
    this->subtypes = subtypes;
}

QVector<Clazz*> Clazz::getInnerClasses()
{
    return innerClasses;
}

void Clazz::setInnerClasses(QVector<Clazz*> innerClasses)
{
    this->innerClasses = innerClasses;
}

QVector<Attribute*> Clazz::getAttributes()
{
    return attributes;
}

void Clazz::setAttributes(QVector<Attribute*> attributes)
{
    this->attributes = attributes;
}

QVector<Method*> Clazz::getMethods()
{
    return methods;
}

void Clazz::setMethods(QVector<Method*> methods)
{
    this->methods = methods;
}

QString Clazz::getStereotype()
{
    return stereotype;
}

void Clazz::setStereotype(QString stereotype)
{
    this->stereotype = stereotype;
}

QString Clazz::toXml()
{
    QString xmi_id = XMLSerializable::typeNameToXmiId.value(className, "UMLClass."+QString::number(XMLSerializable::currentNumber++));
    XMLSerializable::typeNameToXmiId.insert(className, xmi_id);
    QString visibility = "public";
    QString isSpecification = "false";
    QString _namespace = XMLSerializable::currentNamespace;
    QString isRoot = "false";
    QString isLeaf = "false";
    QString isAbstract = "false"; // TODO
    // TODO ustawienie uczestnictwa w asocjacji
    QString participant = "";
    QString generalization = "";
    QString specialization = "";
    QString isActive = "false";

    // generacja bebechów

    QString insideContent = "        <UML:Classifier.feature>\n";

    XMLSerializable::currentOwner = xmi_id;

    for(QVector<Attribute*>::Iterator it = attributes.begin(); it != attributes.end(); it++)
    {
        insideContent += (*it)->toXml();
    }

    for(QVector<Method*>::Iterator it = methods.begin(); it != methods.end(); it++)
    {
        insideContent += (*it)->toXml();
    }

    // generacja podtypow

    for(QVector<Clazz*>::Iterator clazz = subtypes.begin(); clazz != subtypes.end(); clazz++)
    {
        specialization += (*clazz)->getClassName()+" ";
    }

    insideContent += "        </UML:Classifier.feature>\n";

    QString ret = "";

    ret += "      <UML:Class xmi.id=\""+xmi_id+"\" "\
           "name=\""+className+"\" "\
           "visibility=\""+visibility+"\" "\
           "isSpecification=\""+isSpecification+"\" "\
           "namespace=\""+_namespace+"\" "\
           "isRoot=\""+isRoot+"\" "\
           "isLeaf=\""+isLeaf+"\" "\
           "isAbstract=\""+isAbstract+"\" "\
           "participant=\""+participant+"\" "\
           "generalization=\""+generalization+"\" "\
           "specialization=\""+specialization+"\" "\
           "isActive=\""+isActive+"\" >\n";


    ret += insideContent;

    ret += "      </UML:Class>";

    return ret;
}
